package com;

import com.Liuhang.JDBC.util;
import org.junit.jupiter.api.Test;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import com.Liuhang.entity.user;

public class test {
    public static ResultSet rs ;

    public static void main(String[] args) {
            List list = new ArrayList();
            String sql = "select id,name,sex,passwd,dep_name from t_user t,department d WHERE t.pid=d.pid limit 0,5";
            try {
                Statement st = util.getStatement();
                rs = st.executeQuery(sql);
                while (rs.next()){
                    System.out.println("id = "+rs.getObject("id"));
                    System.out.println("name = "+rs.getString("name"));
                    System.out.println("sex = "+rs.getString("sex"));
                    System.out.println("deparment ="+rs.getString("dep_name"));
                    user u1 = new user();
                    u1.setId((Integer) rs.getObject(1));
                    u1.setName(rs.getString("name"));
                    u1.setSex(rs.getString("sex"));
                    u1.setDep_name(rs.getString("dep_name"));
                    //u1.setPhone((Integer) rs.getObject("phone"));

                    list.add(u1);
                }
                for (int i = 0; i <list.size() ; i++) {
                    user u1 = (user) list.get(i);
                    System.out.println(u1);
                }
            } catch (SQLException throwables) {
                throwables.printStackTrace();
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            }

        }
}
